﻿using Company.Core.Interfaces;
using Company.Database;
using Company.Database.Sqlite;
using Company.Plc;
using Company.Plc.NModbus;
using Company.Shell.Dialogs;
using Company.Shell.Interfaces;
using Company.Shell.Services;
using Company.Shell.ViewModels;
using Company.Shell.Views;
using Microsoft.Extensions.DependencyInjection;

namespace Company.Shell.DependencyInjection
{
    public class ServiceManager
    {
        public static IServiceProvider Load()
        {
            var services = new ServiceCollection();

            //注册UI层
            services.AddSingleton<ShellView>();
            services.AddSingleton<ShellViewModel>();
            services.AddSingleton<InitializeView>();
            services.AddSingleton<InitializeViewModel>();
            services.AddSingleton<MainView>();
            services.AddSingleton<MainViewModel>();
            services.AddSingleton<IndexView>();
            services.AddSingleton<IndexViewModel>(); 
            services.AddSingleton<ProgramView>();
            services.AddSingleton<ProgramViewModel>();
            services.AddSingleton<RunView>();
            services.AddSingleton<RunViewModel>();
            services.AddSingleton<HistoryView>();
            services.AddSingleton<HistoryViewModel>();
            services.AddSingleton<CurrentAlarmView>();
            services.AddSingleton<CurrentAlarmViewModel>();
            services.AddSingleton<HistoryAlarmView>();
            services.AddSingleton<HistoryAlarmViewModel>();
            services.AddSingleton<UserView>();
            services.AddSingleton<UserViewModel>();
            services.AddSingleton<ConfigView>();
            services.AddSingleton<ConfigViewModel>();
            services.AddSingleton<ProgramNameView>();
            services.AddSingleton<ProgramNameViewModel>();

            //注册数据库层
            services.AddSingleton<IUserRepository, UserRepository>();
            services.AddTransient<IAlarmRepository, AlarmRepository>();

            //注册业务层
            services.AddSingleton<ISession, Session>();
            services.AddSingleton<IPlc, NModbusPlc>();
            services.AddSingleton<IHardwareMananger, HardwareMananger>();
            services.AddSingleton<IProgramManager, ProgramManager>();
            services.AddSingleton<IMouseManager, MouseManager>();
            services.AddSingleton<IDialogService, DialogService>();
            services.AddSingleton<IConfigManager, ConfigManager>();
            services.AddSingleton<IConfigProvider, ConfigProvider>();
            services.AddSingleton<IRoomManager, RoomManager>();
            services.AddSingleton<ICollectManager, CollectManager>();
            services.AddSingleton<ICacheManager, CacheManager>();
            

            return services.BuildServiceProvider();
        }
    }
}
